var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var BundleConfig = require("AA_BundleConfig");
var EventManager = require("AA_EventManager");
var TipsManager = require("AA_TipsManager");
var UIManager = require("AA_UIManager");
var UIView = require("AA_UIView");
var YunEdit = require("AA_YunEdit");
var EvenType = require("AA_EvenType");
var PlayerDataManager = require("AA_PlayerDataManager");
var Excel = require("AA_Excel");
var ExcelUtil = require("AA_ExcelUtil");
var Const_Hall = require("AA_Const_Hall");
var HallGlobalVariable = require("AA_HallGlobalVariable");
var UIConfig_Home = require("AA_UIConfig_Home");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_DuiHuan = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.yunedit = null;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype._show = function (e) {
    var t = [];
    for (var o = 1; o < arguments.length; o++) {
      t[o - 1] = arguments[o];
    }
  };
  _creator.prototype.onClickDuiHuan = function () {
    var e = this.yunedit.getNowText();
    if ("" == e) {
      TipsManager.TipMgr.showToast("不能为空");
    } else {
      var t = ExcelUtil.ExcelUtil.getSameData(Excel.Excel.shuiguoduihuanma_all, "duihuanmahao", e);
      if (t && t[0]) {
        var o = t[0].id + "" + t[0].duihuanmahao;
        if (PlayerDataManager.PlayerDataMgr.isDuiHuan(o)) {
          TipsManager.TipMgr.showToast("兑换码已使用");
        } else {
          var n = this.getServerTime(t[0].duihuantime);
          if (new Date().getTime() > n) {
            TipsManager.TipMgr.showToast("兑换码已过期");
          } else {
            var i = t[0].duihuanaward;
            this.startDuiHuan(i);
            PlayerDataManager.PlayerDataMgr.saveDuiHuanJiLu(o);
            UIManager.default.closeView(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_Setting);
            UIManager.default.closeView(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_DuiHuan);
          }
        }
      } else {
        TipsManager.TipMgr.showToast("兑换码不存在");
      }
    }
  };
  _creator.prototype.startDuiHuan = function (e) {
    var t = new Const_Hall.GetItemsData();
    t.ids = [];
    t.counts = [];
    for (var o = 0; o < e.length; o++) {
      var n = e[o];
      switch (n[0]) {
        case 1:
          t.ids.push(HallGlobalVariable.default.goldId);
          t.counts.push(n[1]);
          break;
        case 2:
          t.ids.push(HallGlobalVariable.default.diamondId);
          t.counts.push(n[1]);
      }
    }
    t.clickCallBack = function () {
      for (var e = 0; e < t.ids.length; e++) {
        var o = t.ids[e];
        var n = t.counts[e];
        switch (o) {
          case HallGlobalVariable.default.goldId:
            EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Home_Add_Gold, 2, n);
            break;
          case HallGlobalVariable.default.diamondId:
            EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Home_Add_Gold, 3, n);
        }
      }
    };
    UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_GetItems, t);
  };
  _creator.prototype.getServerTime = function (e) {
    return new Date(e).getTime();
  };
  _creator.prototype.onCloseView = function () {
    this._close();
  };
  __decorate([_property(YunEdit.default)], _creator.prototype, "yunedit", undefined);
  return __decorate([_ccclass], _creator);
}(UIView.default);
exports.default = _def_UI_DuiHuan;